package com.game.HUD;

import javax.microedition.khronos.opengles.GL10;

import system.Device;
import system.Graphics;
import system.MyCamera;

import com.game.level.Mission;

public class GUIGame {
	
	private static GL10 gl;
	private static float m_fSrcWidth;
	private static float m_fSrcHeight;
	
	private static boolean s_wasInit = Init();

	static public  void SetMission(Mission level){
		ShowGUIItem.SetMission(level);
	}
	
	static public boolean Init(){
		if (s_wasInit)
			return true;
		gl = Graphics.GetGraphics();
		m_fSrcWidth = Device.GetWidth();
		m_fSrcHeight = Device.GetHeight();
		
		ShowEnemyHP.Init();
		ShowPlayerHP.Init();
		ShowTarget.Init();
		ShowGun.Init();
		ShowGunItem.Init();
		ShowScore.Init();
		ShowMinimap.Init();
		ShowBackground.Init();
		ShowTree.Init();
		ShowYouWin.Init();
		MyCamera.rotateAlpha(0f);

		return true;
	}
	static public void Update(){
		ShowYouWin.Update();
		
		ShowEnemyHP.Update();
		ShowPlayerHP.Update();
		ShowGun.Update();
		ShowMinimap.Update();
	}
	static public void Render(){
		
//		gl.glClearColor(0.4706f, 0.6706f, 0.9137f, 0.8f);
		
		ShowTree.Render();
		ShowBackground.Render();
		
		// 2D
		BeginDraw2D();
		ShowScore.Render();
		ShowEnemyHP.Render();
		ShowPlayerHP.Render();
		ShowTarget.Render();
		ShowGun.Render();
		ShowGunItem.Render();
		ShowMinimap.Render();
		ShowYouWin.Render();
		EndDraw2D();
	}
	
	public static void BeginDraw2D(){
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glPushMatrix();
		gl.glLoadIdentity();
		gl.glOrthof(-m_fSrcWidth/2, m_fSrcWidth/2, -m_fSrcHeight/2, m_fSrcHeight/2, -100.0f, 100.0f);
		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glPushMatrix();
	}
	
	public static void EndDraw2D(){
		gl.glPopMatrix();
		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glPopMatrix();
	}
}
